import os
import socket

if __name__ == "__main__":
    path = os.getcwd()
    print(path)
    tcpServerSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    tcpServerSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
    tcpServerSocket.bind(("", 9000))
    tcpServerSocket.listen(128)
    while True:
        newSockt, ipPort = tcpServerSocket.accept()
        recvData = newSockt.recv(4096)
        recvClientContent = recvData.decode("utf-8")
        print("客服端接收的数据：", recvClientContent)
        with open("static/index.html", "rb") as file:
            fileData = file.read()
        responseLine = "HTTP/1.1 200 OK\r\n"
        responseHeader = "Server: PWS1.0\r\n"
        responseBody = fileData
        responseData = (responseLine + responseHeader + "\r\n").encode(
            "utf-8"
        ) + responseBody

        newSockt.send(responseData)
        newSockt.close()
